<template>
    <div>
        <h2>管理员登录</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <td>
                        <input type="text" v-model="queryInfo.userName"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="queryInfo.password"/>
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" @click="ok" value="登录" class="btn btn-primary" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';
let route=useRoute();
let router=useRouter();
let queryInfo=reactive({
    userName:'',
    password:''
})
const ok=()=>{
    if(queryInfo.userName==''){
        alert('用户名不能为空');
        return;
    }
    if(queryInfo.password==''){
        alert('密码不能为空');
        return;
    }
    axios({
        url:'https://localhost:7289/api/User/Login?UserName='+queryInfo.userName+'&Password='+queryInfo.password,
        method:'get',
        params:{
            queryInfo:queryInfo
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1){
            alert('用户名不存在');
            
        }
        else if(res.data==-2){
            alert('密码不存在');
            
        }
        else{
            alert('登陆成功');
           router.push("/RoomTypeAdd")
        }
        
    })
}
</script>

<style scoped>

</style>